<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .wrap {
            width: 300px;
            height: 550px;
            margin: 50px auto;
            padding: 15px;
            border: 1px solid red;
            text-align: center;
        }

        .wrap img {
            width: 100%;
        }

        b {
            font-size: 20px;
        }

        .box {
            margin-top: 15px;
            margin-bottom: 15px;
        }

        button {
            width: 30px;
            height: 30px;
            border: 1px solid #e6e6e6;
            background-color: #ffffff;
        }

        #num {
            display: inline-block;
            width: 58px;
            height: 28px;
            border-top: 1px solid #e6e6e6;
            border-bottom: 1px solid #e6e6e6;
            vertical-align: middle;
            margin-left: -4px;
            margin-right: -4px;
            text-align: center;
            line-height: 28px;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <img src="2.jpg" alt="">
        <p>纪梵希 小羊皮口红304</p>
        <b>￥ 340</b>
        <div class="box">
            数量
            <button>-</button>
            <span id="num">0</span>
            <button>+</button>
        </div>
        <p>总价￥：<span class="total">0</span></p>
    </div>
    <script>
        // 获取加减按钮
        var sub = document.getElementsByTagName('button')[0]
        var add = document.getElementsByTagName('button')[1]
        var total1 = document.getElementsByClassName('total')[0]
        console.log(sub, add, num, total1)
        sub.onclick = function () {
            if (num.innerHTML > 0) {
                num.innerHTML--
            }
            total1.innerHTML = num.innerHTML * 340
        }
        add.onclick = function () {
            num.innerHTML++
            total1.innerHTML = num.innerHTML * 340
        }
    </script>
</body>

</html>